<?php

namespace App\Admin\Forms;

use App\Models\Contract;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class ContractUrlUpload extends Form implements LazyRenderable
{
    use LazyWidget;

    public function handle(array $input)
    {
        $input['url'] = config('filesystems.disks.qiniu.domains.https') . $input['url'];
        $resutl = Contract::updateOrCreate(['id' => $input['id']], $input);
        if ($resutl) {
            return $this->response()->success('修改成功')->refresh();
        } else {
            return $this->response()->error('修改失败')->refresh();
        }
    }

    public function
    default()
    {

        return [
            // 展示上个页面传递过来的值
            // 'enterprise_project_id' => $this->payload['enterprise_project_id'],
            // 'name'       => $this->payload['name'],
            // 'materials_name'       => $this->payload['materials_name'],
            'id' => $this->payload['id'],
            'url' => $this->payload['url'],
        ];
    }

    public function form()
    {
        $this->hidden('id');
        // $this->text('name', '设计服务名称')->required();
        // $this->text('materials_name', '资料名称')->required();
        // $this->multipleFile('materials', '资料');
        $this->file('url', '最终合同');
    }
}
